home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / library / language.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  4KB  |  144 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopuslib.h"
  32. #include "stringdata.h"
  33. #include "ppdata.h"
  34.  
  35. typedef struct {
  36.     ULONG ckID;
  37.     ULONG ckSize;
  38. } ChunkHeader;
  39.  
  40. __asm __saveds DoReadStringFile(register __a0 struct StringData *stringdata,
  41.     register __a1 char *filename)
  42. {
  43.     int a,size,*ptr;
  44.     StringHeader *header;
  45.     String *string;
  46.     char *cptr;
  47.     struct DefaultString *defstr;
  48.     struct Library *PPBase;
  49.     int file,test[3];
  50.     struct Process *myproc;
  51.     APTR wsave;
  52.  
  53.     myproc=(struct Process *)FindTask(NULL);
  54.     wsave=myproc->pr_WindowPtr;
  55.  
  56.     if (!stringdata) return(0);
  57.     if (!stringdata->string_table) {
  58.         if (!(stringdata->string_table=AllocMem(stringdata->string_count*4,MEMF_CLEAR)))
  59.             return(0);
  60.     }
  61.  
  62.     if (stringdata->string_buffer) {
  63.         FreeMem(stringdata->string_buffer,stringdata->string_size);
  64.         stringdata->string_buffer=NULL;
  65.     }
  66.  
  67.     defstr=stringdata->default_table;
  68.  
  69.     for (a=0;a<stringdata->string_count;a++) {
  70.         if (!defstr[a].string) break;
  71.         stringdata->string_table[defstr[a].string_id]=defstr[a].string;
  72.     }
  73.  
  74.     myproc->pr_WindowPtr=(APTR)-1;
  75.     if (filename && (file=Open(filename,MODE_OLDFILE))) {
  76.         Read(file,(char *)test,12);
  77.         if (test[0]=='PX20' || test[0]=='PP11' || test[0]=='PP20') {
  78.             Close(file);
  79.             if ((PPBase=OpenLibrary("powerpacker.library",0))) {
  80.                 ppLoadData(filename,
  81.                     DECR_NONE,
  82.                     MEMF_CLEAR,
  83.                     &stringdata->string_buffer,
  84.                     &stringdata->string_size,
  85.                     NULL);
  86.                 CloseLibrary(PPBase);
  87.             }
  88.         }
  89.         else {
  90.             if (test[0]==ID_FORM && test[2]==ID_OSTR) {
  91.                 Seek(file,0,OFFSET_END);
  92.                 if ((stringdata->string_size=Seek(file,0,OFFSET_BEGINNING))>0 &&
  93.                     (stringdata->string_buffer=AllocMem(stringdata->string_size,0)))
  94.                     Read(file,stringdata->string_buffer,stringdata->string_size);
  95.             }
  96.             Close(file);
  97.         }
  98.     }
  99.     myproc->pr_WindowPtr=wsave;
  100.  
  101.     if (stringdata->string_buffer) {
  102.         ptr=(int *)stringdata->string_buffer;
  103.         header=(StringHeader *)&stringdata->string_buffer[12];
  104.  
  105.         if (ptr[0]!=ID_FORM || ptr[2]!=ID_OSTR ||
  106.             header->header_id!=ID_STHD ||
  107.             header->version<stringdata->min_version) {
  108.             FreeMem(stringdata->string_buffer,stringdata->string_size);
  109.             stringdata->string_buffer=NULL;
  110.         }
  111.         else {
  112.             cptr=(char *)header+sizeof(StringHeader);
  113.  
  114.             for (a=0;a<header->stringcount;a++) {
  115.                 string=(String *)cptr;
  116.                 if (string->chunk_id==ID_STRN) {
  117.                     if (string->string_id>=0 &&
  118.                         string->string_id<stringdata->string_count)
  119.                         stringdata->string_table[string->string_id]=cptr+sizeof(String);
  120.                 }
  121.                 size=string->chunk_size+sizeof(ChunkHeader);
  122.                 if (size%2) ++size;
  123.                 cptr+=size;
  124.                 if (cptr>=(stringdata->string_buffer+stringdata->string_size)) break;
  125.             }
  126.         }
  127.     }
  128.     return(1);
  129. }
  130.  
  131. void __asm __saveds DoFreeStringFile(register __a0 struct StringData *stringdata)
  132. {
  133.     if (stringdata) {
  134.         if (stringdata->string_buffer) {
  135.             FreeMem(stringdata->string_buffer,stringdata->string_size);
  136.             stringdata->string_buffer=NULL;
  137.         }
  138.         if (stringdata->string_table) {
  139.             FreeMem(stringdata->string_table,stringdata->string_count*4);
  140.             stringdata->string_table=NULL;
  141.         }
  142.     }
  143. }
  144.